Creating a Text Label

This example demonstrates how to create a label with a text label style in a specific position on the terrain. This example uses the IPosition81 (Copy, Pitch), ILabelStyle81 (FontName, Italic, BackgroundColor, Scale), ITerrainLabel81, ICreator81 (CreatePosition, CreateLabelStyle, CreateTextLabel), IColor81 (FromBGRColor, SetAlpha, and INavigate81 (FlyTo) properties and methods.

 

function CreateTextLabel()

      {

      try

      {

      //

      // B.  Create position for label

      //

      {

      // B1. Set position  input parameters (San Francisco shore)

      var dXCoord = -122.49460;

      var dYCoord = 37.78816;

      var dAltitude = 100.0;

      var eAltitudeTypeCode = 0; // AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

      var dYaw = 0.0;

      var dPitch = 0.0;

      var dRoll = 0.0;

      var dDistance = 500;

 

      // B2. Create Position

      var cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);

      }

 

      //

      // C.  Create label style for label

      //

      {

      // C1. Create label syle

      cLabelStyle = sgworld.Creator.CreateLabelStyle();

 

      // C2. Change label style settings

      {

      var nBGRValue = 0xFF0000;  // Blue

      var dAlpha = 0.5;        // 50% opacity

      var cBackgroundColor = cLabelStyle.BackgroundColor;     // Get label style background color

      cBackgroundColor.FromBGRColor(nBGRValue);               // Set background to blue

      cBackgroundColor.SetAlpha(dAlpha);                      // Set transparency to 50%

      cLabelStyle.BackgroundColor = cBackgroundColor;         // Set label style background color

      cLabelStyle.FontName = "Arial";                         // Set font name to Arial

      cLabelStyle.Italic = true;                              // Set label style font to italic

      cLabelStyle.Scale = 3;                                  // Set label style scale

      }

      }

 

      //

      // D. Create text label using label style

      //

      {

      // D1. Set label style params

      var tText = "Skyline";

 

      // D2. Create label style

      var cTextLabel = sgworld.Creator.CreateTextLabel(cPos, tText, cLabelStyle, "", "TextLabel");

      }

 

      //

      // E. FlyTo text label

      //

      {

      var cFlyToPos = cPos.Copy();

      cFlyToPos.Pitch = -89.0; // Set camera to look downward on text label

      sgworld.Navigate.FlyTo(cFlyToPos);

      }

      }

      catch (e)

      {

      alert("Unexpected error: " + e.description);

      }

      }